<template>
	<view class="container">
		<view class="c-input">
			<input type="number" @input="onLogMobile" v-model="logMobile" placeholder="请输入手机号" />
		</view>
		<view class="c-input c-pos">
			<input type="number" @input="onLogCode" v-model="logCode" placeholder="请输入验证码" />
			<button type="primary" :disabled="blnDisabled_code" size="mini" class="c-input-btn c-regcode" @click="onGetRegCode">获取验证码</button>
		</view>
		<view class="c-input">
			<button type="primary" :disabled="blnDisabled_btn" class="c-input-btn" @click="onChkCode">确认绑定</button>
		</view>
	</view>
</template>

<script>
	let pageApp = getApp();
	export default {
		data() {
			return {
				logMobile: "",
				logCode: "",
				blnDisabled_btn: true,
				blnDisabled_code: true,
				blnIsSend: false
			}
		},
		methods: {
			onLogMobile() {
				if (!this.blnIsSend) {
					this.blnDisabled_code = this.checkIsEmpty(this.logMobile, "000000");
				}
			},
			onLogCode() {
				this.blnDisabled_btn = this.checkIsEmpty(this.logMobile, this.logCode);
			},
			onGetRegCode() {
				// 数据基础验证
				if (this.checkMobileCode(this.logMobile)) {
					uni.showToast({
						icon: "none",
						title: "手机号格式有误！"
					})
				} else {
					this.blnDisabled_code = true;
					// 准备请求数据
					let apiData = {
						url: pageApp.globalData.url + "/BindingPhoneMsgCheck",
						data: {
							"Mobile": this.logMobile
						},
						method: "POST",
						success: (d) => {
							if (d.data.code == "001") {
								this.blnIsSend = true;
								uni.showToast({
									icon: "none",
									title: "短信发送成功！"
								})
							} else {
								uni.showToast({
									icon: "none",
									title: d.data.msg
								})
							}
						}
					}
					// 发送数据请求
					this.vjAjaxData(apiData);
				}
			},
			onChkCode() {
				// 基础验证
				if (this.logCode.trim().length != 6) {
					uni.showToast({
						icon: "none",
						title: "验证码长度有误！"
					})
				} else {
					this.blnDisabled_code = true;
					// 准备请求数据
					let apiData = {
						url: pageApp.globalData.url + "/BindingPhone",
						data: {
							"Mobile": this.logMobile,
							"CheckCode": this.logCode
						},
						method: "POST",
						success: (d) => {
							if (d.data.code == "001") {
								uni.showToast({
									title: "绑定成功！",
									success: () => {
										// 返回登录页
										setTimeout(() => {
											uni.navigateTo({
												url: "../MyCenter"
											})
										}, 3000)
									}
								})
							} else {
								uni.showToast({
									icon: "none",
									title: d.data.msg
								})
							}
						}
					}
					// 发送数据请求
					this.vjAjaxData(apiData);
				}
			}
		}
	}
</script>

<style>
</style>
